<template>
    <div class="user-center-box">
        <div class="head-portrait">
            <div class="circular"></div>
        </div>
        <div class="picture">
            <div class="photo">&#xe63c;</div>
        </div>
        <div class="user-info">
            <p class="name">{{userName}}</p>
            <p class="info">房主</p>
        </div>

        <div class="message">
            <div class="item">
                <span>&#xe600;</span>
                房 间 号：{{room.id}}
            </div>
            <div class="item">
                <span>&#xe618;</span>
                盘口金额：{{allowcreditquota}}
            </div>
            <div class="item">
                <span>&#xe68c;</span>
                房间租期：{{room.end}}
            </div>
            <div class="item">
                <span>&#xe65a;</span>
                房间状态：
                <span
                        class="open"
                        style="color: #FF8D24"
                        @click="status(0)"
                        v-if="room.status === 1">开启</span>
                <span
                        class="close"
                        @click="status(1)"
                        style="color: #FF2045"
                        v-else>关闭</span>
            </div>
            <div class="item noborder">
                <span>&#xe623;</span>
                强制登录盘口：
                <span
                        class="open"
                        style="color: #FF8D24"
                        @click="polling_login(0)"
                        v-if="room.polling_login === 1">开启</span>
                <span
                        class="close"
                        @click="polling_login(1)"
                        style="color: #FF2045"
                        v-else>关闭</span>
            </div>
        </div>


        <div class="lists">
            <item :to="{name: 'room-manage'}">
                <span>&#xe80f;</span>
                房间管理
            </item>
            <item :to="{name: 'room-odds'}">
                <span>&#xe8b4;</span>
                赔率设定
            </item>
            <item :to="{name: 'room-users', query: {room_id: this.room.id}}">
                <span>&#xe604;</span>
                在线用户
            </item>
            <item :to="{name: 'room-give', query: {room_id: this.room.id}}">
                <span>&#xe934;</span>
                赠送金币
            </item>
            <item :to="{name: 'room-cash', query: {room_id: this.room.id}}">
                <span>&#xe608;</span>
                资金提现
            </item>
            <item :to="{name: 'room-claim', query: {room_id: this.room.id}}">
                <span>&#xe618;</span>
                索取金币
            </item>
            <item :to="{name: 'room-water', query: {room_id: this.room.id}}">
                <span>&#xe60d;</span>
                房间流水
            </item>
            <item :to="{name: 'room-pay', query: {room_id: this.room.id}}">
                <span>&#xe63a;</span>
                用户支出
            </item>
            <item :to="{name: 'room-order', query: {room_id: this.room.id}}">
                <span>&#xe8b4;</span>
                下注记录
            </item>
            <item :to="{name: 'room-actor', query: {room_id: this.room.id}}">
                <span>&#xe858;</span>
                演员设置
            </item>
            <item :to="{name: 'room-handicap', query: {room_id: this.room.id}}">
                <span>&#xe637;</span>
                盘口设置
            </item>
            <item :to="{name: 'room-p'}">
                <span>&#xe611;</span>
                修改密码
            </item>
        </div>
        <div class="btn">
            <!--<mt-button type="primary" class="go" @click="go">进入房间</mt-button>-->
            <router-link class="goin" :to="{name: 'factory-login'}">进入房间</router-link>
        </div>
    </div>
</template>

<script>
    import apiUrl from '@/api/apiUrl'
    import {Toast} from 'mint-ui'
    import Item from '../../../components/item'
    export default {
        name: "index",
        data () {
            return {
                userName: sessionStorage.getItem('user_name'),
                room: {},
                allowcreditquota: null
            }
        },
        beforeRouteEnter(to, from, next) {
            next(vm => {
                vm.setData()
            })
        },
        components: {
            Item
        },
        methods: {
            polling_login(state=0) {
                let params = {
                    params: {
                        state: state
                    }
                }
                this.$http.get(apiUrl.room.pollingLogin, params).then(res => {
                    if (res.data.code === 0) {
                        this.room.polling_login = state
                    } else {
                        Toast(res.data.msg)
                    }
                })
            },
            status(sta = 1) {
                let res = confirm(`是否要${sta === 1? '开启': '关闭'}房间`)
                if (!res) {
                    return;
                }
                let params = {
                    params: {
                        room_id: this.room.id,
                        status: sta
                    }
                }
                this.$http.get(apiUrl.room.roomSwitched, params).then(res => {
                    if (res.data.code === 0) {
                        Toast('操作成功')
                        this.room.status = sta
                    } else {
                        Toast('操作失败')
                    }
                })
            },
            setData() {
                this.$http.get(apiUrl.room.roomInfo).then(res => {
                    if(res.data.code === 0)
                    {
                        this.$set(this, 'room', res.data.result)
                    } else {
                        Toast(res.data.msg)
                    }
                }).catch(err => {
                    Toast(err);
                })
                this.$http.get(apiUrl.room.membersMbinfo).then(res => {
                    if (res.data.code === 0) {
                        this.allowcreditquota = res.data.result.allowcreditquota
                    } else {
                        Toast(res.data.msg)
                    }
                }).catch(err => {
                    Toast(err);
                })
            },
            go () {
                this.$route.push({name: 'factory-login'})
            }
        }
    }
</script>

<style scoped lang="less">
    @import "style";
</style>